package com.jz.community.basecomm.utils;

import android.app.Activity;
import android.os.CountDownTimer;
import android.widget.TextView;

import com.jz.community.basecommunity.R;


/**
 * Created by Tony.Fan on 2018/3/21 08:59
 * <p>
 * 定时验证码
 */
public class TimeUtils extends CountDownTimer {

    private Activity activity;
    TextView text;

    private TimeUtils(long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);// 参数依次为总时长,和计时的时间间隔
    }

    public TimeUtils(long millisInFuture, long countDownInterval, Activity activity, TextView text) {
        super(millisInFuture, countDownInterval);
        this.activity = activity;
        this.text = text;
    }

    @Override
    public void onFinish() {// 计时完毕时触发
        if (!activity.isFinishing()) {
            text.setText(activity.getResources().getString(R.string.get_id_again));
            text.setClickable(true);
        }
    }

    @Override
    public void onTick(long millisUntilFinished) {// 计时过程显示
        if (!activity.isFinishing()) {
            text.setClickable(false);
            text.setText(millisUntilFinished / 1000 + activity.getResources().getString(R.string.second));
        }
    }
}
